package org.admin.entity.dto;

import core.validate.Rule;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.admin.entity.BaseDto;

import java.util.List;
import java.util.Objects;

@EqualsAndHashCode(callSuper = true)
@Data
public class AppDto extends BaseDto<AppDto> {
    protected AppDto inst(){ return this; }

    public AppDto(){
        addRule(new Rule<?>[] {
            Rule.Number("id")
                    .min(0, "指定应用ID错误"),
            Rule.String("module")
                    .regex("^[a-zA-Z][0-9a-zA-Z-_]*$", "模块名称格式错误")
                    .max(16,"模块名称长度错误"),
            Rule.String("name")
                    .between(1, 16, "应用名称长度错误"),
            Rule.String("detail")
                    .max(200, "应用描述长度错误"),
            Rule.String("picture"),
            Rule.Number("current").min(1, "当前页数不正确"),
            // .integer("无效的页数"),
            Rule.Number("size").onPreCheck(
                    value -> Objects.requireNonNullElse(value, 20)
            ).min(1, "当前数据条目不正确"),
            Rule.Array("ids").min(1, "未指定删除项"),
        });
    }
    private Integer id;
    private String module;
    private String name;
    private String detail;
    private String picture;
    private List<Integer> ids;
    private int current = 1;
    private int size = 20;
}
